<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="css/common.css"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
    <script src="assets/js/jquery.min.js"></script>
</head>
<body>
<div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="index.html" class="navbar-brand">后台管理</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="index.html">首页</a></li>
                <li><a href="#" target="_blank">网站首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li><a href="#">管理员</a></li>
                <li><a href="#">修改密码</a></li>
                <li><a href="#">退出</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container clearfix">
    <div class="sidebar-wrap">
        <div class="sidebar-title">
            <h1>菜单</h1>
        </div>
        <div class="sidebar-content">
            <ul class="sidebar-list">
                <li>
                    <a href="#"><i class="icon-font">&#xe003;</i>常用操作</a>
                    <ul class="sub-menu">
                        <li><a href="index.html"><i class="icon-font">&#xe008;</i>用户管理</a></li>
                        <li><a href="products.html"><i class="icon-font">&#xe005;</i>作品管理</a></li>
                        <li><a href="sowing.html"><i class="icon-font">&#xe006;</i>轮播图管理</a></li>
                        <li><a href="index.html"><i class="icon-font">&#xe004;</i>留言管理</a></li>
                        <li><a href="index.html"><i class="icon-font">&#xe012;</i>评论管理</a></li>
                        <li><a href="index.html"><i class="icon-font">&#xe052;</i>友情链接</a></li>
                        <li><a href="index.html"><i class="icon-font">&#xe033;</i>广告管理</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="icon-font">&#xe018;</i>系统管理</a>
                    <ul class="sub-menu">
                        <li><a href="system.html"><i class="icon-font">&#xe017;</i>系统设置</a></li>
                        <li><a href="system.html"><i class="icon-font">&#xe037;</i>清理缓存</a></li>
                        <li><a href="system.html"><i class="icon-font">&#xe046;</i>数据备份</a></li>
                        <li><a href="system.html"><i class="icon-font">&#xe045;</i>数据还原</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/jscss/admin/design/">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/jscss/admin/design/">作品管理</a><span class="crumb-step">&gt;</span><span>新增作品</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="/jscss/admin/design/add" method="post" id="myform" name="myform" enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody>
                            <tr>
                                <th width="120"><i class="require-red" >*</i>图片名称：</th>
                                <td>
                                    <input class="common-text required" id="title" name="title" size="50" value="" type="text">
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>缩略图：</th>
                                <td><img  alt="" src="" id="image" width="100px"/></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>缩略图：</th>
                                <td><input name="smallimg" id="smallimg" type="file" width="150px"><!--<input type="submit" onclick="submitForm('/jscss/admin/design/upload')" value="上传图片"/>--></td>
                            </tr>
                            <tr>
                            <tr>
                                <th><i class="require-red">*</i>位置：</th>
                                <td>
                                     <select name="colId" id="position" class="required">
                                    <option value="">请选择轮播图位置</option>
                                    <option value="1">1</option><option value="2">2</option><option value="3">3</option>
                                    <option value="4">4</option><option value="5">5</option>
                                		</select>
                                </td>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="button" id="sum">
                                    <input class="btn btn6" onClick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
</body>
 <script type="text/javascript">
 function getUrlParam(name)
	{
	 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	 var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	 if (r!=null) return unescape(r[2]); 
	 return null; //返回参数值
} 
 $(document).ready(function(){
	$.post("selectsowing", {"photo.id":getUrlParam("id")}, function(data){
		$("#title").val(data.name);
		$("#position").val(data.position);
		$("#image").attr("src",data.url);
		})
		
		$("#sum").click(function(){
			var name = $("#title").val();
			var position = $("#position").val();
			var form = new FormData();
			form.append("photo.name",name);
			form.append("file",$("#smallimg")[0].files[0]);
			form.append("photo.position",position);
			form.append("photo.id",getUrlParam("id"));
			form.append("photo.url",$("#image").attr("src"));
			$.ajax({
					url:"saveUpdate",
					type:"POST",
					data: form,
					saync: false,
		            contentType: false,
		            processData: false,
		            success:function(data){
		                  if(data.isSuccess){
		                      alert("修改成功!")
		                  }else{
		                      alert("修改失败!")
		                  }
		              },
		           erro:function(data){
		                  alert("上传失败!")
		                  window.location.href="register.html"
		              }
				})
		   })
 })        
</script>
</html>